package com.yong.sbd.biz.mybatis.mapper;

import com.yong.sbd.biz.mybatis.entity.SysUserRole;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * 用户角色关联Mapper接口
 *
 * @author Kang Yong
 * @date 2025/10/24
 * @since 1.0.0
 */
@Mapper
public interface SysUserRoleMapper {

    /**
     * 根据ID查询用户角色关联
     *
     * @param id {@link Long}
     * @return {@link SysUserRole}
     */
    @Select("SELECT * FROM sys_user_role WHERE id = #{id}")
    SysUserRole selectById(Long id);

    /**
     * 根据用户ID查询用户角色关联
     *
     * @param userId {@link Long}
     * @return {@link List<SysUserRole>}
     */
    @Select("SELECT * FROM sys_user_role WHERE user_id = #{userId}")
    List<SysUserRole> selectByUserId(Long userId);

    /**
     * 根据角色ID查询用户角色关联
     *
     * @param roleId {@link Long}
     * @return {@link List<SysUserRole>}
     */
    @Select("SELECT * FROM sys_user_role WHERE role_id = #{roleId}")
    List<SysUserRole> selectByRoleId(Long roleId);

    /**
     * 插入用户角色关联
     *
     * @param userRole {@link SysUserRole}
     * @return int
     */
    @Insert("INSERT INTO sys_user_role(user_id, role_id) VALUES(#{userId}, #{roleId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SysUserRole userRole);

    /**
     * 根据ID删除用户角色关联
     *
     * @param id {@link Long}
     * @return int
     */
    @Delete("DELETE FROM sys_user_role WHERE id = #{id}")
    int deleteById(Long id);

    /**
     * 根据用户ID删除用户角色关联
     *
     * @param userId {@link Long}
     * @return int
     */
    @Delete("DELETE FROM sys_user_role WHERE user_id = #{userId}")
    int deleteByUserId(Long userId);
}